using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.Windows.Data;

namespace PlanetWPF.Toolbelt.Converters
{
    /// <summary>
    /// MonthYearHeaderConverter converts the month&year properties of 
    /// VisibleMonth to string with CultureInfo
    /// </summary>
    public sealed class MonthYearHeaderConverter : IValueConverter
    {
        /// <summary>
        /// convert the month and year to a proper string
        /// </summary>
        /// <param name="value">DateTime</param>
        /// <param name="targetType">string</param>
        /// <param name="parameter">null</param>
        /// <param name="culture">CultureInfo</param>
        /// <returns>title string</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is DateTime)
            {
                if (culture == null)
                {
                    culture = CultureInfo.CurrentCulture;
                }

                if (culture.DateTimeFormat != null)
                {
                    DateTime date = (DateTime)value;
                    return date.ToString(culture.DateTimeFormat.YearMonthPattern, culture.DateTimeFormat);
                }
            }

            return String.Empty;
        }

        /// <summary>
        /// Not Supported
        /// </summary>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
